package com.netintech.service;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.pattern.color.ANSIConstants;
import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase;

/**
 * @Description: 自定义颜色配置类（我这里是每种日志级别定义一种颜色）
 * @Author: changjianbao
 * @CreateDate: 2019/8/7 9:43
 * @UpdateUser: changjianbao
 * @UpdateDate: 2019/8/7 9:43
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class LogColor extends ForegroundCompositeConverterBase<ILoggingEvent> {

    @Override
    protected String getForegroundColorCode(ILoggingEvent event) {
        Level level = event.getLevel();
        switch(level.toInt()) {
            case Level.ERROR_INT:
                return ANSIConstants.RED_FG;
            case Level.WARN_INT:
                return ANSIConstants.YELLOW_FG;
            case Level.INFO_INT:
                return ANSIConstants.DEFAULT_FG;
            case Level.DEBUG_INT:
                return ANSIConstants.GREEN_FG;
            case Level.TRACE_INT:
                return ANSIConstants.DEFAULT_FG;
            default:
                return ANSIConstants.DEFAULT_FG;
        }
    }
}
